package cn.itrip.biz.controller;


import cn.itrip.beans.dtos.Dto;
import cn.itrip.beans.dtos.ErrorCode;
import cn.itrip.beans.dtos.InputDto;
import cn.itrip.beans.vo.biz.GetImg;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomBed;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomByHotel;
import cn.itrip.beans.vo.biz.ListQueryHotelRoomByHotelVo;
import cn.itrip.biz.service.IItripHotelRoomService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;


/**
 * <p>
 * 酒店房间表 前端控制器
 * </p>
 *
 * @author 滕召伟
 * @since 2020-02-27
 */
@RestController
@RequestMapping("/biz/api/hotelroom")
public class ItripHotelRoomController {
    @Resource
    IItripHotelRoomService iItripHotelRoomService;

    @PostMapping(value = "/queryhotelroombyhotel", produces = "application/json;charset=utf-8")
    public Dto listQueryHotelRoomByHotel(@RequestBody ListQueryHotelRoomByHotel byHotel) {
        if (byHotel.getHotelId() == null) {
            return InputDto.error(ErrorCode.BIZ_PASS_VALUE_NULL);
        } else {
            List<ListQueryHotelRoomByHotelVo> list = iItripHotelRoomService.listQueryHotelRoomByHotel(byHotel);
            List<List<ListQueryHotelRoomByHotelVo>> vos = new ArrayList<>();
            for (ListQueryHotelRoomByHotelVo vo : list) {
                List<ListQueryHotelRoomByHotelVo> voList = new ArrayList<>();
                voList.add(vo);
                vos.add(voList);
            }
            return InputDto.data(vos);
        }
    }

    @GetMapping(value = "/queryhotelroombed", produces = "application/json;charset=utf-8")
    public Dto listQueryHotelRoomBed() {
        List<ListQueryHotelRoomBed> list = iItripHotelRoomService.listQueryHotelRoomBedById(1);
        return InputDto.data(list);
    }

    @GetMapping("/getimg/{hotelId}")
    public Dto GetImg(@PathVariable("hotelId") Integer hotelId) {
        if (hotelId == null) {
            return InputDto.error(ErrorCode.BIZ_PASS_VALUE_NULL);
        } else {
            List<GetImg> imgs = iItripHotelRoomService.GetImg(hotelId);
            return InputDto.data(imgs);
        }
    }
}

